
function initOrgChart(chart_container_id , updateMode){
	
	$("ul.orgChartList").jOrgChart({chartElement : '#'+chart_container_id});
	
	// in update mode only
	if (updateMode){
		$('.jOrgChart .node').off().dblclick(function(){ _onDoubleClickOrgChartNode($(this))}); 
		$('.jOrgChart .node > input[type="text"]').blur(function() {_onBlurOrgChartTextfield($(this))}).hide();
	}
}

function _onDoubleClickOrgChartNode(node) {
	node.find('label:first').hide();
	node.find('input[type="text"]:first').show().focus();
}

function _onBlurOrgChartTextfield(tfObj) {
	tfObj.hide();
	tfObj.siblings("label:first").html(tfObj.val()).show();
}

function deleteOrgChartLeafNode(obj){ 
    if(confirm('Are you sure, you want to delete this department?')){
          $("form").prepend('<input type="hidden" id="deletedNodeId" name="deletedNodeId" value="'+ $(obj).attr("id") +'"/>');  
          //if add dep only
          //$("#name").attr('disabled' , 'disabled');
          //$("#description").attr('disabled' , 'disabled');

          $("form").attr("action", "DepartmentDeleteProcess");
          $("form").submit();	
    }	  
}

function initPage() {

	$("body").prop("class", "pure-skin-mine");
	$("form").prop("class", "pure-form");

	// init calendar elements
	$(".caldr").datepicker({
		dateFormat : 'dd/mm/yy',
		changeMonth : true,
		changeYear : true,
		yearRange : "-30:+5"
	});

	// init file upload elements
	initFileInputElements();

	// $("select:not(.auto_off)").each(function(){alert("init :: "+this.name + "
	// :: "+$(this).find("option[selected='selected']").size() )})
	// add default option to dropdown lists
	$("select:not(.auto_off)")
			.prepend("<option value=''>من فضلك اختر</option>").each(function() {
				if ($(this).find("option[selected='selected']").size() == 0)
					this.selectedIndex = 0
			});
	$("select.auto_add_all").prepend("<option value='0'>الكل</option>").each(
			function() {
				if ($(this).find("option[selected='selected']").size() == 0)
					this.selectedIndex = 0
			});

	// style buttons with pure framework
	$("input[type='button']").addClass("pure-button");
	$("input[type='submit']").addClass("pure-button pure-button-primary");

	// add margin between horizontal radio group
	$("input[type='radio']").css("margin-left", "2px");
	$("input[type='radio']").next().css("margin-right", "15px");

	// special css to handle the category radios properly
	$("input[type='radio'][name='category']").css("margin-right", "2px");
	$("input[type='radio'][name='category']").next().css("margin-left", "15px");

	// add margin between horizontal checkbox group
	$("input[type='checkbox']").css("margin-left", "2px");
	$("input[type='checkbox']").next().css("margin-right", "15px");

	appendCommonQueryStrToReportsMenuItems();

	$("form").attr('novalidate', 'novalidate');
	$("form").validate(
					{

						// ignore: ":hidden:not(input:file)", // to allow hidden
						// fields to validated

						errorPlacement : function(error, element) { // to adjust
							// the radio
							// and
							// checkbox
							// group msg
							// placement
							if ($(element).is("input:file")) {
								if (element.closest("label").parent().find(
										"span[class='requiredField']").length > 0)
									error
											.insertAfter(element
													.closest("label")
													.parent()
													.find(
															"span[class='requiredField']"));
								else
									error.insertAfter(element.closest("label"))
							} else {
								// to adjust display of category radios error
								// message
								if (element.parent().prop("id") == "category_radio_container")
									element.parent().prepend(error);
								else
									error.appendTo(element.parent());
							}
						}
					});

	initRequiredFields();
}

/*
 
function appendCommonQueryStrToReportsMenuItems() {

	$("li.reports_menu_items > ul > li > a").each(
			function() {

				// initially equal to the original href
				var newHref = $(this).prop("href");

				if (newHref.indexOf("reqRepTitle=") == -1) { // if the common
					// query string
					// param does
					// not exist
					newHref += ((newHref.indexOf("?") == -1) ? "?" : "&")
							+ "reqRepTitle="
							+ encodeURIComponent($(this).html());
					$(this).prop("href", newHref);
				}
			});
}


// init the notifications websocket

var wsConnection;

function connect() {
	wsConnection = new WebSocket("ws://127.0.0.1:8080/MMP/JobOrdersNotifier");
	
	wsConnection.onopen = function(){
		   console.log('WebSocket connection has been opened');
	}

	wsConnection.onclose = function(){
		   console.log('WebSocket connection has been closed');
	}

	wsConnection.onerror = function(error){
		   console.log('WebSocket connection has error detected: ' + error);
	}

	wsConnection.onmessage = function(event) {
		var data = event.data;
		// var container = document.getElementById("container");
		// container.innerHTML=data;
		// alert(event.data);
		// if(data.trim().length == 0)
		// $("#notifications_Container").html("").parent("tr").hide();
		// else
		$("#notifications_Container").html(event.data);//.parent("tr").show();
	}
}

$(function() {
	connect()
});

*/